package com.soft.javase.day06.datetime;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/24
 */
public class DateDemo1 {
    public static void main(String[] args) throws ParseException {
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = sdf1.parse("2014-05-25");
        Date date2 = sdf1.parse("2012-12-28");

        System.out.println("-----2014-5-25到2012-12-28中间有多少天？-----");
        long ms = date1.getTime() - date2.getTime();
        long days = ms / (24 * 60 * 60 * 1000);
        System.out.println("天数差: " + days + " 天\n");

        System.out.println("-----距离当前时间500天后的日期和时间、星期-----");
        Calendar calendar1 = Calendar.getInstance();
        calendar1.add(Calendar.DAY_OF_YEAR,500);
        String[] weeks = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
        int year = calendar1.get(Calendar.YEAR);
        int month = calendar1.get(Calendar.MONTH)+1;
        int day = calendar1.get(Calendar.DAY_OF_MONTH);
        int hour = calendar1.get(Calendar.HOUR_OF_DAY);
        int minute = calendar1.get(Calendar.MINUTE);
        int second = calendar1.get(Calendar.SECOND);
        int week = calendar1.get(Calendar.DAY_OF_WEEK);
        System.out.println(year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second+" "+weeks[week-1]);

        Date date = calendar1.getTime();
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss EEEE");
        String dateStr = sdf2.format(date);
        System.out.println(dateStr+"\n");

        System.out.println("-----你出生的当天是星期几？-----");
        String birthStr = "2001-06-30";
        SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd");
        Date birthDate = sdf3.parse(birthStr);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTime(birthDate);
        int dayOfWeek = calendar2.get(Calendar.DAY_OF_WEEK);
        System.out.println(birthStr+"是" + weeks[dayOfWeek-1]);

    }
}
